clear all
set more off

global chemin "HERE indicated path to the main folder"
cd "$chemin\data"

use final_IHME22, clear
drop if recipient_name == "Unallocated/Unspecified"
* we drop 2019 and 2020 because we don't have bilateral data but just global data
drop if year >= 2019
gen MCP = 0
replace MCP = 1 if year <1993 /* active until December 1992 */
replace MCP = 1 if year == 1995
replace MCP = 1 if year >1999 & year <2009 /* active in FY 99/00  and from 01/2001 to 12/2008*/
replace MCP = 1 if year >2016 /*active from 01/2017 to 12/2020*/ 


* Intsrument construction
	* Part 1 : probability of receiving FP aid when MCP is not active
	gen aid_pc = (rmh_fp_dah_20_US >0)
	bys recipient_name : egen aid = mean(aid_pc) if MCP == 0
	bys recipient_name : egen FPr = mean(aid)

* instrument 1 : Probability of receiving FP aid when MCP is not active * share channelled through NGO during OBAMA term * policy
	gen instrument1 = FPr * share_NGOUS_Obama * MCP
* instrument 2 : Probability of receiving FP aid when MCP is not active * share channelled through NGO when MCP not active * policy
	gen instrument2 = FPr * share_NGOUS_MCP * MCP

* Creation of controls
	gen lngdppc = ln(GDPpc_r)
	gen lnpopr = ln(pop_r)
	gen laidfp = ln(rmh_fp_dah_20 + ((rmh_fp_dah_20^2 +1)^0.5))
	gen laidUS = ln(rmh_fp_dah_20_US + ((rmh_fp_dah_20_US^2 +1)^0.5))

	gen laidfp2 = ln(rmh_fp_dah_20 + 1)
	gen laidUS2 = ln(rmh_fp_dah_20_US + 1)

	egen id_o = group(donor)
	egen id_dr = group(donor recipient_name)
	egen id_r = group( recipient_name)
	gen fert2 = fertility_r *fertility_r

xtset id_dr year
global controls  lngdppc lnpopr poverty_r
global controls1 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r
global controls2 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r polity2
global controls3 lngdppc lnpopr poverty_r life_expectencyfe_r incidenceHIV_r HIV1549_r fert2 fertility_r adofertility_r maternalmortality_r polity2 UN_dr 

* controls interacted with FPr*ShareNGOr
foreach i of varlist $controls3 {
	gen `i'_int = `i' * FPr * share_NGOUS_Obama
}


* Definition of different set of controls 
global controlsi  L.lngdppc* L.lnpopr* L.poverty_r*    																				
global controls1i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r*
global controls2i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r* L.polity2* 
* will exclude the EU and the BMGF because no data on UN vote...
global controls3i L.lngdppc* L.lnpopr* L.poverty_r* L.life_expectencyfe_r* L.HIV1549_r* L.incidenceHIV_r* L.fert2* L.fertility* L.adofertility* L.maternalmortality_r* L.polity2* L.UN_dr* 


label variable laidUS "Log of US FP aid\$_{rt-1}$"
label variable instrument1 "MCP\$_{t}$ * FP\$_{r}$ * shareONG\$_{r}$"

/* Baseline results*/
ivreghdfe laidfp $controls2i (laidUS =instrument1 ),  absorb(id_dr i.year##i.id_o)  cluster(recipient_name donor) first
gen in_sample4 =e(sample)

/* Estimates outputs - Table 1 */ 
eststo clear
	eststo A0: ivreghdfe laidfp $controls2i laidUS 	if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) 
	eststo A1: ivreghdfe laidfp $controls2i L.laidUS	if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor )
	eststo A2: ivreghdfe laidfp $controls2i L2.laidUS	if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor )
	eststo A3: ivreghdfe laidfp $controls2i L3.laidUS	if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) 
	eststo A4: ivreghdfe laidfp $controls3i laidUS	if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) 
	eststo A5: ivreghdfe laidfp $controls3i L.laidUS	if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) 
	eststo A6: ivreghdfe laidfp $controls3i L2.laidUS	if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor )
	eststo A7: ivreghdfe laidfp $controls3i L3.laidUS	if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) 
	
	eststo B0: ivreghdfe laidfp $controls2i (laidUS =instrument1 ) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first savefirst savefprefix(st0) saverf saverfprefix(rf0)
	eststo B1: ivreghdfe laidfp $controls2i (L.laidUS=L.instrument1 ) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first savefirst savefprefix(st1) saverf saverfprefix(rf1)
	eststo B2: ivreghdfe laidfp $controls2i (L2.laidUS=L2.instrument1 ) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first savefirst savefprefix(st2) saverf saverfprefix(rf2)
	eststo B3: ivreghdfe laidfp $controls2i (L3.laidUS=L3.instrument1 ) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first savefirst savefprefix(st3) saverf saverfprefix(rf3)
	eststo B4: ivreghdfe laidfp $controls3i (laidUS =instrument1 ) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first savefirst savefprefix(st4) saverf saverfprefix(rf4)
	eststo B5: ivreghdfe laidfp $controls3i (L.laidUS=L.instrument1 ) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first savefirst savefprefix(st5) saverf saverfprefix(rf5)
	eststo B6: ivreghdfe laidfp $controls3i (L2.laidUS=L2.instrument1 ) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first savefirst savefprefix(st6) saverf saverfprefix(rf6)
	eststo B7: ivreghdfe laidfp $controls3i (L3.laidUS=L3.instrument1 ) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first savefirst savefprefix(st7) saverf saverfprefix(rf7)
	foreach j of numlist 0/3 {
		estadd local DRFE "Yes": B`j'
		estadd local DYFE "Yes": B`j'
		foreach i of numlist 1 {
			estadd local control`i' "Yes": B`j'
		}
		foreach i of numlist 2 {
			estadd local control`i' "Yes": B`j'
		}	
		foreach i of numlist 3 {
			estadd local control`i' "Yes": B`j'
		}
		foreach i of numlist 4 {
			estadd local control`i' "No" : B`j'
		}
	}
	foreach j of numlist 4/7 {
		estadd local DRFE "Yes": B`j'
		estadd local DYFE "Yes": B`j'
		foreach i of numlist 1 {
			estadd local control`i' "Yes": B`j'
		}
	foreach i of numlist 4 {
			estadd local control`i' "Yes": B`j'
		}
	}	
	
	esttab A* using "..\output\baselineresults.tex" ,  replace ///
		drop(* )  ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mtitles("(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)")
	esttab A* using "..\output\baselineresults.tex" ,  append ///
		drop(* )  ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mtitles("\${k=0}$" "\${k=1}$" "\${k=2}$" "\${k=3}$" "\${k=0}$" "\${k=1}$" "\${k=2}$" "\${k=3}$")
	esttab A* using "..\output\baselineresults.tex" ,  append ///
		drop(* )  ///
		b(a2) se(a2) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mgroups("Panel A: OLS Estimates - Independent Variable: USFPaid\$_{rt-k}$" , pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles
	esttab A* using "..\output\baselineresults.tex" ,  append ///
		keep( laidUS ) rename(L3.laidUS laidUS L2.laidUS laidUS L.laidUS laidUS ) ///
		b(3) se(3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		coeflabel(laidUS "FPAid\$_{drt}$" ) ///
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se   nomtitles
	
	
	esttab rf* using "..\output\baselineresults.tex" ,  append ///
		drop(* )  ///
		b(a2) se(a2) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mgroups("Panel B: Reduced Form Estimates - Ind. Var.: FP\$_{r}$ * shareNGO\$_{r}$ * MCP\$_{t-k}$" , pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles
	esttab rf* using "..\output\baselineresults.tex" ,  append ///
		keep( instrument1 ) rename(L3.instrument1 instrument1 L2.instrument1 instrument1 L.instrument1 instrument1 ) ///
		b(3) se(3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		coeflabel(instrument1 "FPAid\$_{drt}$" ) ///
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se   nomtitles

		
	esttab B* using "..\output\baselineresults.tex" ,  append ///
		drop(* )  ///
		b(a2) se(a2) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mgroups("Panel C: 2SLS Estimates - Independent Variable: USFPaid\$_{rt-k}$" , pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles
	esttab B* using "..\output\baselineresults.tex" ,  append ///
		keep( laidUS ) rename(L3.laidUS laidUS L2.laidUS laidUS L.laidUS laidUS ) ///
		b(3) se(3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		coeflabel(laidUS "FPAid\$_{drt}$" ) ///
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se   nomtitles
	
	
	esttab st* using "..\output\baselineresults.tex" ,  append ///
		drop(* )  ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mgroups("Panel D: First-Stage Estimates - Ind. Var.: FP\$_{r}$ * shareNGO\$_{r}$ * MCP\$_{t-k}$" , pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles
	esttab st* using "..\output\baselineresults.tex" ,  append ///
		keep( instrument1 ) rename(L3.instrument1 instrument1 L2.instrument1 instrument1 L.instrument1 instrument1 ) ///
		b(3) se(3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		coeflabel(instrument1 "USFPAid\$_{drt-k}$" ) ///
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se   nomtitles
	esttab B* using "..\output\baselineresults.tex" ,  append ///
		drop(*) /// /*Estimates we want to show */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonotes collabels(none) nonum nomtitles se /// /* some options on formatings */
		scalars("N Obs." "df_a_nested Donor-Rec. pairs" "N_clust1 Recipient" "widstat K-P. F-Stat" "cdf Cragg-Donald F" ///
		"DRFE Donor-Rec. FE" ///
		"DYFE Donor-Year FE" ///
		"control1 Controls\$_{rt-1}$" ///
		"control4 Controls\$_{drt-1}$"  )  sfmt(a3) 

	
	
	
eststo clear	
	
/* Estimates outputs - Tables B.1 and B.2 */ 
	ivreghdfe laidfp   L3.laidUS L2.laidUS L.laidUS laidUS if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) 
	est store O1
	ivreghdfe laidfp $controlsi  L3.laidUS L2.laidUS L.laidUS laidUS  if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) 
	est store O2 
	ivreghdfe laidfp $controls1i L3.laidUS L2.laidUS L.laidUS laidUS  if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) 
	est store O3
	ivreghdfe laidfp $controls2i L3.laidUS L2.laidUS L.laidUS laidUS  if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) 
	est store O4
	* here we lose the EU and the BMGF
	ivreghdfe laidfp $controls3i L3.laidUS L2.laidUS L.laidUS laidUS  if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor )
	est store O5

	ivreghdfe laidfp   (L3.laidUS L2.laidUS L.laidUS laidUS =L3.instrument1 L2.instrument1 L.instrument1 instrument1 ) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first savefirst savefprefix(st0) saverf saverfprefix(rf0)
	est store B1
	estadd local DRFE "Yes": B1
	estadd local DYFE "Yes": B1
	test laidUS + L.laidUS = 0
	estadd scalar test1= r(p): B1
	test laidUS + L.laidUS + L2.laidUS = 0
	estadd scalar test2= r(p): B1
	test laidUS + L.laidUS + L2.laidUS + L3.laidUS = 0
	estadd scalar test3= r(p): B1
	
	foreach i of numlist 1 {
		estadd local control`i' "No": B1
	}
	foreach i of numlist 2 {
		estadd local control`i' "No": B1
	}	
	foreach i of numlist 3 {
		estadd local control`i' "No": B1
	}
	foreach i of numlist 4 {
		estadd local control`i' "No": B1
	}
	ivreghdfe laidfp $controlsi  (L3.laidUS L2.laidUS L.laidUS laidUS =L3.instrument1 L2.instrument1 L.instrument1 instrument1 ) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first savefirst savefprefix(st1) saverf saverfprefix(rf1)
	est store B2
	estadd local DRFE "Yes": B2
	estadd local DYFE "Yes": B2
	test laidUS + L.laidUS = 0
	estadd scalar test1= r(p): B2
	test laidUS + L.laidUS + L2.laidUS = 0
	estadd scalar test2= r(p): B2
	test laidUS + L.laidUS + L2.laidUS + L3.laidUS = 0
	estadd scalar test3= r(p): B2
	foreach i of numlist 1 {
		estadd local control`i' "Yes": B2
	}
	foreach i of numlist 2 {
		estadd local control`i' "No": B2
	}	
	foreach i of numlist 3 {
		estadd local control`i' "No": B2
	}
	foreach i of numlist 4 {
		estadd local control`i' "No": B2
	}
	ivreghdfe laidfp $controls1i (L3.laidUS L2.laidUS L.laidUS laidUS =L3.instrument1 L2.instrument1 L.instrument1 instrument1 ) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first savefirst savefprefix(st2) saverf saverfprefix(rf2)
	est store B3
	estadd local DRFE "Yes": B3
	estadd local DYFE "Yes": B3
	test laidUS + L.laidUS = 0
	estadd scalar test1= r(p): B3
	test laidUS + L.laidUS + L2.laidUS = 0
	estadd scalar test2= r(p): B3
	test laidUS + L.laidUS + L2.laidUS + L3.laidUS = 0
	estadd scalar test3= r(p): B3
	foreach i of numlist 1 {
		estadd local control`i' "Yes": B3
	}
	foreach i of numlist 2 {
		estadd local control`i' "Yes": B3
	}	
	foreach i of numlist 3 {
		estadd local control`i' "No": B3
	}
	foreach i of numlist 4 {
		estadd local control`i' "No": B3
	}
	ivreghdfe laidfp $controls2i (L3.laidUS L2.laidUS L.laidUS laidUS =L3.instrument1 L2.instrument1 L.instrument1 instrument1 ) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first savefirst savefprefix(st3) saverf saverfprefix(rf3)
	est store B4
	estadd local DRFE "Yes": B4
	estadd local DYFE "Yes": B4
	test laidUS + L.laidUS = 0
	estadd scalar test1= r(p): B4
	test laidUS + L.laidUS + L2.laidUS = 0
	estadd scalar test2= r(p): B4
	test laidUS + L.laidUS + L2.laidUS + L3.laidUS = 0
	estadd scalar test3= r(p): B4
	foreach i of numlist 1 {
		estadd local control`i' "Yes": B4
	}
	foreach i of numlist 2 {
		estadd local control`i' "Yes": B4
	}	
	foreach i of numlist 3 {
		estadd local control`i' "Yes": B4
	}
	foreach i of numlist 4 {
		estadd local control`i' "No": B4
	}
	ivreghdfe laidfp $controls3i (L3.laidUS L2.laidUS L.laidUS laidUS =L3.instrument1 L2.instrument1 L.instrument1 instrument1 ) if in_s == 1,  absorb(id_dr i.year##i.id_o )  cluster(recipient_name donor ) first savefirst savefprefix(st4) saverf saverfprefix(rf4)
	est store B5
	estadd local DRFE "Yes": B5
	estadd local DYFE "Yes": B5
	test laidUS + L.laidUS = 0
	estadd scalar test1= r(p): B5
	test laidUS + L.laidUS + L2.laidUS = 0
	estadd scalar test2= r(p): B5
	test laidUS + L.laidUS + L2.laidUS + L3.laidUS = 0
	estadd scalar test3= r(p): B5
	foreach i of numlist 1 {
		estadd local control`i' "Yes": B5
	}
	foreach i of numlist 2 {
		estadd local control`i' "Yes": B5
	}	
	foreach i of numlist 3 {
		estadd local control`i' "Yes": B5
	}
	foreach i of numlist 4 {
		estadd local control`i' "Yes": B5
	}

	* OLS - part*
		esttab O1 O2 O3 O4 O5 /*OLS*/ using "..\output\appsimulresult.tex" ,  replace ///
		drop(* )  ///
		b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		  substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mtitles("(1)" "(2)" "(3)" "(4)" "(5)")
		esttab O1 O2 O3 O4 O5 /*OLS*/ using "..\output\appsimulresult.tex" ,  append ///
		keep(L3.laidUS L2.laidUS L.laidUS laidUS ) order(laidUS L.laidUS L2.laidUS L3.laidUS) ///
		b(3) se(3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		coeflabel(L3.laidUS "Log of US FP aid\$ _{rt-3}$" ///
		L2.laidUS "Log of US FP aid\$ _{rt-2}$" ///
		L.laidUS "Log of US FP aid\$ _{rt-1}$" ///
		laidUS  "Log of US FP aid\$ _{rt}$" ) ///
		 substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mgroups("A: OLS Estimates - Family planning aid\$_{drt}$" , pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles

	* Reduced Form *
		esttab rf0* rf1* rf2* rf3* rf4*   using "..\output\appsimulresult.tex" ,  append /// 
		keep(L3.instrument1 L2.instrument1 L.instrument1 instrument1)  order(instrument1 L.instrument1 L2.instrument1 L3.instrument1) ///
		coeflabel(L3.instrument1 "MCP\$_{t-3}$ * FP\$_{r}$ * shareONG\$_{r}$" ///
		L2.instrument1 "MCP\$_{t-2}$ * FP\$_{r}$ * shareONG\$_{r}$" ///
		L.instrument1 "MCP\$_{t-1}$ * FP\$_{r}$ * shareONG\$_{r}$" ///
		instrument1 "MCP\$_{t}$ * FP\$_{r}$ * shareONG\$_{r}$" ) ///
		b(3) se(3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		 substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		mgroups("B: Reduced Form - Dep. Var : Family planning aid\$_{drt}$" , pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles

	* 2nd Stage*
		esttab B1 B2 B3 B4 B5 /*2SLS*/  using "..\output\appsimulresult.tex" ,  append ///
		keep(L3.laidUS L2.laidUS L.laidUS laidUS  ) order(laidUS L.laidUS L2.laidUS L3.laidUS)  ///
		coeflabel(L3.laidUS "Log of US FP aid\$ _{rt-3}$" ///
		L2.laidUS "Log of US FP aid\$ _{rt-2}$" ///
		L.laidUS "Log of US FP aid\$ _{rt-1}$" ///
		laidUS  "Log of US FP aid\$ _{rt}$" ) ///
		b(3) se(3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
		  substitute($ \$) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
		 mgroups("C: 2SLS  - Dep. Var :  Family planning aid\$_{drt}$" , pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles

	
		esttab B1 B2 B3 B4 B5 /*2SLS*/  using "..\output\appsimulresult.tex" ,  append ///
		drop(*) /// /*Estimates we want to show */
		substitute($ \$ ) /// /* Formatting label */
		nonumber  nolines nogap title() booktabs fragment  noobs nonotes collabels(none) nonum nomtitles se /// /* some options on formatings */
		scalars("N Obs." "df_a_nested Donor-recipient pair" "N_clust1 Recipient" "widstat K-P. F-Stat" "cdf Cragg-Donald F" ///
		"test1 p-value \$\sum_{k=0}^{1} USFP_{rt-k}$=0" ///
		"test2 p-value \$\sum_{k=0}^{2} USFP_{rt-k}$=0" ///
		"test3 p-value \$\sum_{k=0}^{3} USFP_{rt-k}$=0" ///
		"DRFE Donor-Recipient FE" ///
		"DYFE Donor-Year FE" ///
		"DRFE Region-Year FE" ///
		"control1 Population and income controls\$ _{rt-1}$" ///
		"control2 Health and fertility controls\$ _{rt-1}$" ///
		"control3 Political controls\$ _{rt-1}$" ///
		"control4 Bilateral controls\$ _{drt-1}$"  )  sfmt(a3) 


		
		esttab st3* using "..\output\appsimulresult1st.tex" ,  replace ///
			drop(* )  ///
			b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
			substitute($ \$ ) /// /* Formatting label */
			nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
			mtitles("(1)" "(2)" "(3)" "(4)")
		esttab st3* using "..\output\appsimulresult1st.tex" ,  append ///
			drop(* )  ///
			b(a3) se(a3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
			substitute($ \$ ) /// /* Formatting label */
			nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  /// /* some options on formatings */
			mgroups("D: First-stage - Dep. Var : US Family planning aid" , pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles 
		esttab st3*  using "..\output\appsimulresult1st.tex" ,  append ///
			keep(L3.instrument1 L2.instrument1 L.instrument1 instrument1) order(instrument1 L.instrument1 L2.instrument1 L3.instrument1)  ///
			coeflabel(L3.instrument1 "MCP\$_{t-3}$ * FP\$_{r}$ * shareONG\$_{r}$" ///
			L2.instrument1 "MCP\$_{t-2}$ * FP\$_{r}$ * shareONG\$_{r}$" ///
			L.instrument1 "MCP\$_{t-1}$ * FP\$_{r}$ * shareONG\$_{r}$" ///
			instrument1 "MCP\$_{t}$ * FP\$_{r}$ * shareONG\$_{r}$" ) ///
			b(3) se(3) starlevels({$^{*}$} 0.10 {$^{**}$} 0.05 {$^{***}$} 0.01) /// /* number format and stars */
			substitute($ \$) /// /* Formatting label */
			nonumber  nolines nogap title() booktabs fragment  noobs nonum nonotes collabels(none) se  ///
			mtitles("US FP aid\$ _{rt}$" "US FP aid\$ _{rt-1}$" "US FP aid\$ _{rt-2}$" "US FP aid\$ _{rt-3}$")
			




